package com.maychat.interceptor;

import com.maychat.config.Consts;
import com.maychat.exception.NoAuthException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) {
        if (StringUtils.isBlank(req.getHeader(Consts.AUTH)))
            throw new NoAuthException("登录超时，请重新登录");
        return true;
    }
}
